import js from "@eslint/js";
import globals from "globals";
import prettierPlugin from "eslint-plugin-prettier";
import eslintConfigPrettier from "eslint-config-prettier";
import { defineConfig } from "eslint/config";

export default defineConfig([
	{
		files: ["**/*.{js,mjs,cjs}"],
		plugins: { js, prettier: prettierPlugin },
		extends: ["js/recommended"],
		languageOptions: { globals: globals.browser },
	},
	{
		rules: {
			// 基础 JavaScript 规则
			"no-var": "error",
			"no-void": "error",
			radix: "error",
			eqeqeq: ["error", "always", { null: "ignore" }],
			"no-restricted-globals": ["error", "isFinite", "isNaN"],
			// "no-console": "error",
			"no-return-assign": "error",
			curly: "error",

			// 变量和类型相关
			"new-cap": "error",

			// 函数相关
			"prefer-rest-params": "error",
			"max-params": ["error", 3],
			"max-nested-callbacks": ["error", 3],
			"prettier/prettier": "error",
		},
	},
	eslintConfigPrettier,
]);
